package com.example.mybatis_plus.handle;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @author GJH
 * @version V1.0
 * @Package com.example.mybatis_plus.handle
 * @date 2022/4/27 21:42
 * @Copyright © XXXX-XXXX  搬砖工程师
 */
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {
    //自动填充，执行添加操作
    @Override
    public void insertFill(MetaObject metaObject) {
        this.setFieldValByName("createTime",new Date(),metaObject);
        this.setFieldValByName("updateTime",new Date(),metaObject);
        this.setFieldValByName("version",1, metaObject);
    }
   //mq执行修改操作
    @Override
    public void updateFill(MetaObject metaObject) {
        this .setFieldValByName("updateTime",new Date(),metaObject);
    }
}
